﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace Task255555
{
    class Program
    {
        static void Main(string[] args)
        {
            //定义数据库
            string connString = "server=.;database=Game;Integrated Security=true";
            //创建连接对象
            SqlConnection conn = new SqlConnection(connString);
            //打开数据库连接
            conn.Open();
            //检测数据库连接是否打开
            if (conn.State==ConnectionState.Open)
            {
                //统计产品数量(放入sql语句)
                string countSql = "select count(*) from Games ";
                //创建Command对象
                SqlCommand countCmd = new SqlCommand(countSql,conn);
                //执行SQL命令
                string count = countCmd.ExecuteScalar().ToString();
                //汇总总金额
                string sumSql = "select sum(Stock*Price) from Games";
                //创建Command对象
                SqlCommand sumCmd = new SqlCommand(sumSql,conn);
                //执行SQL命令
                string sum = sumCmd.ExecuteScalar().ToString();
                //计算商品的平均价格
                string avgSql = "select avg(Price) from Games";
                //创建Command对象
                SqlCommand avgCmd = new SqlCommand(avgSql,conn);
                //执行SQL命令
                string avg = avgCmd.ExecuteScalar().ToString();
                Console.WriteLine("MHYS科技公司产品统计");
                Console.WriteLine("***************************************************");
                Console.WriteLine("产品的个数：{0}",count);
                Console.WriteLine("产品的总金额（总价值）：{0}元",sum);
                Console.WriteLine("产品的平均价格：{0}元",avg);
            }
        }
    }
}
